home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / a-calend.ads < prev    next >
Text File  |  1996-01-30  |  4KB  |  99 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --                         A D A . C A L E N D A R                          --
  6. --                                                                          --
  7. --                                 S p e c                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.8 $                              --
  10. --                                                                          --
  11. -- This specification is adapted from the Ada Reference Manual for use with --
  12. -- GNAT.  In accordance with the copyright of that document, you can freely --
  13. -- copy and modify this specification,  provided that if you redistribute a --
  14. -- modified version,  any changes that you have made are clearly indicated. --
  15. --                                                                          --
  16. ------------------------------------------------------------------------------
  17.  
  18. package Ada.Calendar is
  19.  
  20.    type Time is private;
  21.  
  22.    --  Declarations representing limits of allowed local time values. Note that
  23.    --  these do NOT constrain the possible stored values of time which may well
  24.    --  permit a larger range of times (this is explicitly allowed in Ada 9X).
  25.  
  26.    subtype Year_Number  is Integer range 1901 .. 2099;
  27.    subtype Month_Number is Integer range 1 .. 12;
  28.    subtype Day_Number   is Integer range 1 .. 31;
  29.  
  30.    subtype Day_Duration is Duration; -- range 0.0 .. 86_400.0
  31.    --  We don't have subtype ranges yet for real types, fix this later ???
  32.  
  33.    function Clock return Time;
  34.  
  35.    function Year    (Date : Time) return Year_Number;
  36.    function Month   (Date : Time) return Month_Number;
  37.    function Day     (Date : Time) return Day_Number;
  38.    function Seconds (Date : Time) return Day_Duration;
  39.  
  40.    procedure Split
  41.      (Date    : Time;
  42.       Year    : out Year_Number;
  43.       Month   : out Month_Number;
  44.       Day     : out Day_Number;
  45.       Seconds : out Day_Duration);
  46.  
  47.    function Time_Of
  48.      (Year    : Year_Number;
  49.       Month   : Month_Number;
  50.       Day     : Day_Number;
  51.       Seconds : Day_Duration := 0.0)
  52.       return    Time;
  53.  
  54.    function "+" (Left : Time;     Right : Duration) return Time;
  55.    function "+" (Left : Duration; Right : Time)     return Time;
  56.    function "-" (Left : Time;     Right : Duration) return Time;
  57.    function "-" (Left : Time;     Right : Time)     return Duration;
  58.  
  59.    function "<"  (Left, Right : Time) return Boolean;
  60.    function "<=" (Left, Right : Time) return Boolean;
  61.    function ">"  (Left, Right : Time) return Boolean;
  62.    function ">=" (Left, Right : Time) return Boolean;
  63.  
  64.    Time_Error : exception;
  65.  
  66. private
  67.    pragma Inline (Clock);
  68.  
  69.    pragma Inline (Year);
  70.    pragma Inline (Month);
  71.    pragma Inline (Day);
  72.  
  73.    pragma Inline ("+");
  74.    pragma Inline ("-");
  75.  
  76.    pragma Inline ("<");
  77.    pragma Inline ("<=");
  78.    pragma Inline (">");
  79.    pragma Inline (">=");
  80.  
  81.    --  Time is represented as a signed duration from the base point which is
  82.    --  what Unix calls the EPOCH (i.e. 12 midnight (24:00:00), Dec 31st, 1969,
  83.    --  or if you prefer 0:00:00 on Jan 1st, 1970). Since Ada allows dates
  84.    --  before this EPOCH value, the stored duration value may be negative.
  85.  
  86.    --  The time value stored is typically a GMT value, as provided in standard
  87.    --  Unix environments. If this is the case then Split and Time_Of perform
  88.    --  required conversions to and from local times. The range of times that
  89.    --  can be stored in Time values depends on the declaration of the type
  90.    --  Duration, which must at least cover the required Ada range represented
  91.    --  by the declaration of Year_Number, but may be larger (we take full
  92.    --  advantage of the new permission in Ada 9X to store time values outside
  93.    --  the range that would be acceptable to Split). The Duration type is a
  94.    --  real value representing a time interval in seconds.
  95.  
  96.    type Time is new Duration;
  97.  
  98. end Ada.Calendar;
  99.